﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class KeyG_Trigger : MonoBehaviour
{
    public bool apear = false;
    public GameObject showBall;
    Transform key;
    Transform light;
    float Y;


    private void Awake()
    {
        Y = transform.position.y;

        key = transform;
        //key = transform.Find("pPlane3");
        //key.GetComponent<BoxCollider>().enabled = false;
        //key.GetComponent<MeshRenderer>().enabled = false;
        //key.GetComponent<MeshRenderer>().enabled = false;
        light = transform.Find("Point Light");
        //light.gameObject.SetActive(false);
    }

    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        key.transform.Rotate(Vector3.up * 30f * Time.deltaTime);
        //transform.Find("pPlane3").transform.Rotate(Vector3.up * 30f * Time.deltaTime);
        //transform.position = new Vector3(transform.position.x, Y + Random.Range(0, 0.2f)*Time.deltaTime, transform.position.z);

        if (apear)
        {
            GetComponent<BoxCollider>().enabled = true;
            key.GetComponent<MeshRenderer>().enabled = true;
            light.gameObject.SetActive(true);
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag.Equals("Player"))
        {
            //other.GetComponent<Bag>().isHasSKey = true;
            other.GetComponent<Tools>().isHasKeyRoom2 = true;
            showBall.GetComponent<BindShowText>().setShowText("看你玩到这份上金钥匙白给你了。\n（其实还没做完）");
            showBall.GetComponent<BindShowText>().showShowText();
            light.gameObject.SetActive(false);
            Destroy(gameObject);
        }
    }
}
